import React from 'react';
import { inject, observer } from 'mobx-react';
import { Button,Spin } from "antd";
import { WeaTableNew } from "comsMobx";
import { WeaLocaleProvider, WeaReqTop, WeaRightMenu, WeaTab,WeaDialog,WeaAlertPage} from 'ecCom';
import {Condition} from '../list/listCondition';
import {InfoFeedbackDialog} from '../../components/dialog/InfoFeedbackDialog';
import {SpecialDialog} from '../../components/dialog/SpecialDialog';
import {RewardDialog} from '../../components/dialog/RewardDialog';
import {Text} from '../util/text';
import { QuickSiftDialog } from '../dialog/QuickSiftDialog';
const text = new Text();
const getLabel = WeaLocaleProvider.getLabel;
const WeaTable = WeaTableNew.WeaTable;

@inject("infoHandleCardStore")
@observer
class InfoHandleCard extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
        }
    }

    componentDidMount() {
        const {infoHandleCardStore} = this.props;
        const { id, siftId } = this.props.location.query;   //id:上报信息id     siftId:待编信息id
        if (typeof (siftId) != 'undefined') {
            infoHandleCardStore.setState({ 'showTab': false });
        } else {
            infoHandleCardStore.setState({ 'showTab': true });
        }
        infoHandleCardStore.getAddInfoTypeCondition({ id: id, siftId: siftId });    //初始化卡片condition
    }

    handleChange(data) {
        // if (Object.keys(data)[0] == "isused") {
        // }
    }

    getTopButtons = () => {
        const {infoHandleCardStore} = this.props;
        let btns = [];
        btns.push(
            infoHandleCardStore.getTopButton()
        )
        return btns;
    }

    changeTab(key) {
        const {infoHandleCardStore} = this.props;
        infoHandleCardStore.changeTab(key);
    }
    addScore = () => {
        const {infoHandleCardStore} = this.props;
        infoHandleCardStore.rewardDialogStore.getRewardList({'siftId': infoHandleCardStore.siftId,type:'3'});
        infoHandleCardStore.rewardDialogStore.setState({visible:true});
        infoHandleCardStore.setState({ scoreVisible: false });
    }
    delScore = () => {
        const {infoHandleCardStore} = this.props;
        infoHandleCardStore.delScore();
    }

    

    render() {
        const { infoHandleCardStore, infoHandleCardStore: { loadingSpin, isRight,setState,tableStore, scoreTableStore,feedbackDialogStore, specialDialogStore,rewardDialogStore, selectTabKey, status, form, condition} } = this.props;
        const rightMenu = infoHandleCardStore.getRightMenu();
        if (loadingSpin) {
			return <div className="h100" style={{ textAlign: 'center', paddingTop: '300px' }}><Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@ucbo2w`} size="large" /></div>
		}
		if (!isRight) {
			return <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@htktw6`}><div>{getLabel(382663, '暂无权限')}</div></WeaAlertPage>
		}
        let {loading, showTab,scoreVisible} = status;
        const tabs1 = [{ key: "infoHandle", title: text.INFOHANDLE }];
        const tabs2 = [{ key: "infoHandle", title: text.INFOHANDLE }, { key: "infoFeedback", title: text.FEEDBACKINFO }];
        let btns = new Array();
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@fsh903@addScore`} onClick={() => { this.addScore() } } type="primary" shape="circle" icon="plus" size="small" ></Button>);
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@ylrvl8@delScore`} onClick={() => { this.delScore() } } shape="circle" icon="minus" size="small"></Button>);
        return (
            <div className='wea-govern-info'>
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@jmfpli`}
                    datas={rightMenu} >
                    <WeaReqTop ecId={`${this && this.props && this.props.ecId || ''}_WeaReqTop@41nn0k`}
                        title={text.INFOHANDLE}
                        loading={loading}
                        icon={<i className='icon-coms-government' />}
                        iconBgcolor='#f14a2d'
                        buttons={this.getTopButtons() }
                        showDropIcon={true}
                        dropMenuDatas={rightMenu}
                        tabDatas={showTab ? tabs2 : tabs1}
                        selectedKey={selectTabKey}
                        //style={{ padding: '0px 20px 0 20px' }}
                        onChange={this.changeTab.bind(this) }
                        >
                        <div >{selectTabKey == "infoHandle" && <div>
                            <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@bpsisn`} listStore={infoHandleCardStore} form={form} handleChange={this.handleChange.bind(this) } condition={condition} underline={true}></Condition>
                        </div>}</div>
                        <div>{selectTabKey == "infoFeedback" &&
                            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@4e1zml`} className="wea-info-table" comsWeaTableStore={tableStore} needScroll={true}
                                />
                        }
                        </div>
                        <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@73wjjf`}
                            icon="icon-coms-government"
                            iconBgcolor='#f14a2d'
                            title={text.HISTORYSCORE}
                            visible={scoreVisible}
                            style={{ width: 550, height: 450 }}
                            hasScroll= {true}
                            onCancel={() => { setState({ scoreVisible: false }) } }
                            buttons={[
                                (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@8mxlkd@CLOSE`} type="ghost" onClick ={() => { setState({ scoreVisible: false }) } }>{text.CLOSE}</Button>)
                            ]}
                            >
                            <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@vazerb`} buttons={btns} />
                            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@jv1h9e`} className="wea-info-table" comsWeaTableStore={scoreTableStore} needScroll={true}
                                />
                        </WeaDialog>
                        <RewardDialog ecId={`${this && this.props && this.props.ecId || ''}_RewardDialog@jj0rfg`} store={rewardDialogStore} />
                        <InfoFeedbackDialog ecId={`${this && this.props && this.props.ecId || ''}_InfoFeedbackDialog@niaday`} store={feedbackDialogStore} type='2'/>
                        <SpecialDialog ecId={`${this && this.props && this.props.ecId || ''}_SpecialDialog@98usdf`} store={specialDialogStore} />
                        <QuickSiftDialog ecId={`${this && this.props && this.props.ecId || ''}_QuickSiftDialog@ik1dim`} store={infoHandleCardStore} />
                    </WeaReqTop>
                </WeaRightMenu>
            </div>
        )
    }

}

export default InfoHandleCard;